package net.yegong.util;

/**
 * 
 * The Tuple which can contains three different elements.
 * @author cooper
 * 
 */
public final class Tuple3<U, V, W> {

	public Tuple3(U u, V v, W w) {
		this.u = u;
		this.v = v;
		this.w = w;
	}

	public U get1() {
		return u;
	}

	public V get2() {
		return v;
	}

	public W get3() {
		return w;
	}

	@Override
	public String toString() {
		return "[" + u + ", " + v + ", " + w + "]";
	}

	@Override
	public int hashCode() {
		int hash1 = 0;
		int hash2 = 0;
		int hash3 = 0;
		if (u != null) {
			hash1 = u.hashCode();
		}
		if (v != null) {
			hash2 = v.hashCode();
		}
		if (w != null) {
			hash3 = w.hashCode();
		}
		return (((hash1 * 31) ^ hash2) * 31) ^ hash3;
	}

	@Override
	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		if (o instanceof Tuple3<?, ?, ?>) {
			Tuple3<?, ?, ?> t = (Tuple3<?, ?, ?>) o;
			boolean eq1 = (u == t.u) || (u != null && u.equals(t.u)); 
			boolean eq2 = (v == t.v) || (v != null && v.equals(t.v)); 
			boolean eq3 = (w == t.w) || (w != null && w.equals(t.w)); 
			return eq1 && eq2 && eq3;
		}
		return false;
	}

	private U u;
	private V v;
	private W w;
}
